package com.atguigu.spzx.manager.controller;

import com.atguigu.spyx.model.common.Result;
import com.atguigu.spyx.model.common.com.atguigu.spyx.model.entity.product.Brand;
import com.atguigu.spzx.manager.service.BrandService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author LT
 * @create 2023-11-08-19:40
 */
@RestController
@RequestMapping("/admin/product/brand")
public class BrandController {

    @Resource
    BrandService brandService;

    @GetMapping("/findAll")
    public Result findAll(){
        List<Brand> brands = brandService.findAll();
        return Result.ok().data(brands);
    }

    @GetMapping("/page/{pageNum}/{pageSize}")
    public Result page(@PathVariable("pageNum")Integer pageNum,
                        @PathVariable("pageSize")Integer pageSize){
        PageInfo<Brand> pageInfo = brandService.page(pageNum,pageSize);
        return Result.ok().data(pageInfo);
    }

    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable("id")Long id){
        brandService.deleteById(id);
        return Result.ok();
    }

    @GetMapping("/getById/{id}")
    public Result getById(@PathVariable("id")Long id){
       Brand brand = brandService.getById(id);

       return Result.ok().data(brand);
    }

    @PutMapping("/updateById")
    public Result updateById(@RequestBody Brand brand){
        brandService.updateById(brand);
        return Result.ok();
    }

    @PostMapping("/save")
    public Result save(@RequestBody Brand brand){
        brandService.save(brand);
        return  Result.ok();
    }

}
